/*
 * Generator.java
 *
 * Created on July 2, 2006, 12:28 PM
 *
 */

package galronnlp.util;

import java.lang.Thread;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author Daniel A. Galron
 */
public abstract class Generator extends Thread {
    
    protected LinkedList results;
    
    public boolean running = true;
    
    /** Creates a new instance of Generator */
    public Generator() {
        results = new LinkedList();
    }
    
    public void run() {
        running = true;
        this.generate();
        running = false;
    }
    
    public Object getNext() {
        while(results.size() == 0) {}
        synchronized(this.results) {
            return results.removeFirst();
        }
    }
    
    public boolean hasNext() {
        return results.size() > 0;
    }
    
    public abstract void generate();
    
}
